<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class Notice extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('notice');
        if(!$exists){
        $table = $this->table('notice', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '通知' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('read', 'boolean', ['null' => false,'default' => 0,'signed' => false,'comment' => '读',])
			->addColumn('title', 'string', ['limit' => 20,'null' => false,'default' => 0,'signed' => true,'comment' => '标题',])
			->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '内容',])
			->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '接收人ID',])
			->addColumn('launch_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '发起人ID',])
			->addColumn('avatar_url', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '头像跳转地址',])
			->addColumn('content_url', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '内容跳转地址',])
			->addColumn('type', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '类型：0 系统、1 笔记、2 圈子、3 购物',])
			->addColumn('status', 'enum', ['values' => ['0','1']])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '更新时间',])
			->addIndex(['user_id'], ['name' => '_u_id'])
            ->create();
        }
    }
}
